<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm" style="padding-bottom: 500px">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <?php include "../public/substt.php";?>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="business">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=shou_xiang','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=shou_xiang','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>收款信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">收款单号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项类型</label>
                        <div class="layui-input-block">
                            <select id="feilei" name="feilei" lay-filter="feilei"></select>
                            <p class="error" id="feilei_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhai" id="zhai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>到账金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款方</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="duier" class="layui-input duier" onclick="openPage('../public/choose_dealcom.php?dom=duier','80%','80%')">
                            <div class="choose_div" id="duier" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=duier','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>到账方式</label>
                        <div class="layui-input-block">
                            <div id="incdaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>到账账户</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="accid" class="layui-input accid" onclick="openPage('../public/choose_account.php?dom=accid','80%','80%')">
                            <div class="choose_div" id="accid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_account.php?dom=accid','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>到账日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dt" id="dt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>经办人</label>
                        <div class="layui-input-block">
                            <input type="text" name="baner" id="baner" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>收款明细</span></div>
                        <div>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_copy_row">复制行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th><text>*</text>费用项</th>
                            <th><text>*</text>到账金额(元)</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror listerror_list">提示：<span></span></div>
                </div>
            </div>


            <div class="business2 layui-hide">
                <div>
                    <div class="layui-row layui-col-space10">
                        <div class="edittits"><span>扣收信息</span></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label">待扣合计不含本次(元)</label>
                            <div class="layui-input-block">
                                <input type="text" id="daikouallfee" name="daikouallfee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled colorlan">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">本次到款应计管理费(元)</label>
                            <div class="layui-input-block">
                                <input type="hidden" id="lian_guanrate">
                                <input type="text" id="benguanfee" name="benguanfee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label">待扣合计含本次(元)</label>
                            <div class="layui-input-block">
                                <input type="text" id="daikouhanfee" name="daikouhanfee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>本次收款是否扣收</label>
                            <div class="layui-input-block">
                                <select id="iskou" name="iskou" lay-filter="iskou">
                                    <option value="">请选择</option>
                                    <option value="是">是</option>
                                    <option value="否">否</option>
                                </select>
                                <p class="error" id="iskou_error" style="margin: 0;"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item iskoushi layui-hide">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label">本次扣收金额(元)</label>
                            <div class="layui-input-block">
                                <input type="text" name="koufee" id="koufee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">其中管理费扣收(元)</label>
                            <div class="layui-input-block">
                                <input type="text" name="kouguanfee" id="kouguanfee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item iskoushi layui-hide">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label">其中税费扣收(元)</label>
                            <div class="layui-input-block">
                                <input type="text" name="koushuifee" id="koushuifee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">其中其他费扣收(元)</label>
                            <div class="layui-input-block">
                                <input type="text" name="kouqifee" id="kouqifee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item height_auto iskoushi layui-hide">
                    <div class="short_table_list" key="2">
                        <div class="opt-btn-group">
                            <div><span>扣收明细</span></div>
                            <div>
                                <button type="button" onclick="choose_dai_kou_qi_list()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">从其他费待扣明细选择</button>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_copy_row">复制行</button>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                            </div>
                        </div>
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th width="45">序号</th>
                                <th>来源</th>
                                <th><text>*</text>费用项</th>
                                <th><text>*</text>扣收金额(元)</th>
                                <th>款项说明</th>
                            </tr>
                            </thead>
                            <tbody class="short_table_tbody" id="list_kou"></tbody>
                        </table>
                        <div class="listerror listerror_kou">提示：<span></span></div>
                    </div>
                </div>
            </div>


            <?php include '../public/flowqita.php'?>
            <?php include '../public/upinfo.php'?>
        </div>
    </div>
</form>

<?php include 'showrrboxtext.php'?>
<div><?php include '../public/shrrbox_addpage.php'?></div>
<script>
    var param_id = getQueryVariable('id') || 0;
    chu_flow_edit_yushen();

    $("#commentForm").validate({
        rules: {
            zhai: {required: true},
            baner: {required: true},
            dt: {required: true},
        },
        messages:{
            zhai: {required: "请输入"},
            baner: {required: "请输入"},
            dt: {required: "请选择"},
        }
    });


    function choose_dai_kou_qi_list() {
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择项目名称");return false;
        }
        openPage('../public/choose_dai_kou_qi_list.php?page=shou_xiang&enginid='+enginid,'80%','80%');
    }

    $("#daikouallfee").click(function () {
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择项目名称");return false;
        }
        openNavPage('查看应扣费用表信息','lian_yingkou/index.php?status=1&enginid='+enginid);
    });


    var pub_feilei;

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();
        facade.ajax({type: 'get', url: ask_flowdata_edit_shou_xiang, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                chu_flow_qian(data);



                var engininfo = res.data.engininfo
                var account = res.data.account;
                if(engininfo){
                    set_choose_btn('enginid',engininfo.id,engininfo.name);

                    if(engininfo.business == 2){
                        $(".business2").removeClass('layui-hide');
                        $("#lian_guanrate").val(engininfo.lian_guanrate);
                    }else{
                        $(".business2").addClass('layui-hide');
                    }
                    $("#business").val(engininfo.business);

                    set_right_relainfo(engininfo)
                }
                if(account){
                    set_choose_btn('accid',account.id,account.name+'('+account.accnum+')');
                }
                if(data.duier){
                    set_choose_btn('duier',data.duier,data.duier);
                }

                $("#number").val(data.number);
                $("#zhai").val(data.zhai);
                $("#money").val(data.money);
                $("#duier").val(data.duier);
                $("#dt").val(data.dt);
                $("#baner").val(data.baner);
                $("#explain").val(data.explain);
                $("#daikouallfee").val(data.daikouallfee);
                $("#benguanfee").val(data.benguanfee);
                $("#daikouhanfee").val(data.daikouhanfee);
                $("#iskou").val(data.iskou);
                $("#koufee").val(data.koufee);
                $("#kouguanfee").val(data.kouguanfee);
                $("#koushuifee").val(data.koushuifee);
                $("#kouqifee").val(data.kouqifee);

                xiala_zhan_two('feilei', res.data.feilei, data.feilei, 'id', 'name');

                xmselect_dan('incdaotype', res.data.incdaotype, data.incdaotype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#incdaotype").find('xm-select').removeClass('error');
                    }else{
                        $("#incdaotype").find('xm-select').addClass('error');
                    }
                });


                pub_feilei = res.data.feilei;

                var feitype = [];
                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><select class="layui-select feitype">';
                listAddStr += '<option value="">请选择</option>';
                for (var mmm in feitype) {
                    listAddStr += '<option value="'+feitype[mmm].id+'">'+feitype[mmm].name+'</option>';
                }
                listAddStr += '</select></td>';
                listAddStr += '<td><input type="number" class="layui-input money"></td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 1, {}, 'set_key1_add_str');


                var list = res.data.list;
                if(list.length > 0){

                    var feitype = [];
                    var feilei = data.feilei || 0;
                    for (var mmm in pub_feilei){
                        if(pub_feilei[mmm].id == feilei){
                            feitype = pub_feilei[mmm].children;
                        }
                    }

                    for (var key in list){
                        var str = '';
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><select class="layui-select feitype">';
                        str += '<option value="">请选择</option>';
                        for (var mmm in feitype) {
                            if(feitype[mmm].id == list[key].feitype){
                                str += '<option value="'+feitype[mmm].id+'" selected>'+feitype[mmm].name+'</option>';
                            }else{
                                str += '<option value="'+feitype[mmm].id+'">'+feitype[mmm].name+'</option>';
                            }
                        }
                        str += '</select></td>';
                        str += '<td><input type="number" class="layui-input money" value="'+list[key].money+'"></td>';
                        str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                        str += '</tr>';
                        $("#list_list").append(str);
                    }
                }




                var kou_feitype = res.data.kou_feitype[0].children;
                var kouAddStr = '';
                kouAddStr += '<tr>';
                kouAddStr += '<td style="width: 45px">1</td>';
                kouAddStr += '<td><input type="text" class="layui-input daikouqiid disabled" key="0" value="/" disabled></td>';
                kouAddStr += '<td><select class="layui-select feitype" lay-filter="kou_feilei">';
                kouAddStr += '<option value="">请选择</option>';
                for (var mmm in kou_feitype) {
                    kouAddStr += '<option value="'+kou_feitype[mmm].id+'">'+kou_feitype[mmm].name+'</option>';
                }
                kouAddStr += '</select></td>';
                kouAddStr += '<td><input type="number" class="layui-input money"></td>';
                kouAddStr += '<td><input type="text" class="layui-input explain"></td>';
                kouAddStr += '</tr>';
                short_table_opt_func(kouAddStr, 2);

                var kou = res.data.kou;
                if(data.iskou == '是'){
                    $(".iskoushi").removeClass('layui-hide');
                    if(kou.length > 0){
                        for (var key in kou){
                            var str = '';
                            var nums = parseInt(key)+1;
                            str += '<tr>';
                            str += '<td style="width: 45px">'+nums+'</td>';
                            if(kou[key].daikouqiid > 0){
                                str += '<td><input type="text" class="layui-input daikouqiid disabled" key="'+kou[key].daikouqiid+'" value="待扣" disabled></td>';
                                str += '<td><input type="text" class="layui-input feitype disabled" disabled key="'+kou[key].feitype+'" value="'+kou[key].feitype_name+'"></td>';
                                str += '<td><input type="number" class="layui-input money disabled" disabled value="'+kou[key].money+'"></td>';
                                str += '<td><input type="text" class="layui-input explain disabled" disabled value="'+kou[key].explain+'"></td>';
                            }else{
                                str += '<td><input type="text" class="layui-input daikouqiid disabled" key="0" value="/" disabled></td>';
                                str += '<td><select class="layui-select feitype" lay-filter="kou_feilei">';
                                str += '<option value="">请选择</option>';
                                for (var mmm in kou_feitype) {
                                    if(kou_feitype[mmm].id == kou[key].feitype){
                                        str += '<option value="'+kou_feitype[mmm].id+'" selected>'+kou_feitype[mmm].name+'</option>';
                                    }else{
                                        str += '<option value="'+kou_feitype[mmm].id+'">'+kou_feitype[mmm].name+'</option>';
                                    }
                                }
                                str += '</select></td>';
                                str += '<td><input type="number" class="layui-input money" value="'+kou[key].money+'"></td>';
                                str += '<td><input type="text" class="layui-input explain" value="'+kou[key].explain+'"></td>';
                            }

                            str += '</tr>';
                            $("#list_kou").append(str);
                        }
                    }
                }



                update_refresh_row_func()


                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });

        form.on('select(feilei)', function(data){
            var feitype = [];
            var feilei = data.value || 0;
            for (var mmm in pub_feilei){
                if(pub_feilei[mmm].id == feilei){
                    feitype = pub_feilei[mmm].children;
                }
            }

            $.each($("#list_list").children('tr'),function (key,val) {
                var seleStr = '';
                seleStr += '<option value="">请选择</option>';
                for (var mmm in feitype) {
                    seleStr += '<option value="'+feitype[mmm].id+'">'+feitype[mmm].name+'</option>';
                }
                $(this).find('.feitype').html(seleStr);
            });
            jisuan_money_all();
            render_from();

            if(data.value == ''){
                $('#feilei_error').show().text('请选择');
                $('#feilei_error').parent().find('input').addClass('select_error');
            }else{
                $('#feilei_error').hide();
                $('#feilei_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(kou_feilei)', function(data){
            jisuan_koufee_all();
        });


        form.on('select(iskou)', function(data){
            if(data.value == '是') {
                $(".iskoushi").removeClass('layui-hide');
            }else{
                $(".iskoushi").addClass('layui-hide');
            }
            if(data.value == ''){
                $('#iskou_error').show().text('请选择');
                $('#iskou_error').parent().find('input').addClass('select_error');
            }else{
                $('#iskou_error').hide();
                $('#iskou_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.isshen = $(this).attr('isshen') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');
            parseMoney(data);

            data.field.enginid = get_choose_val('enginid');
            data.field.duier = get_choose_val('duier');
            data.field.accid = get_choose_val('accid');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();
                formValid('enginid');
                if(data.field.enginid == undefined || !data.field.enginid){
                    validRes = false;
                }

                if(data.field.feilei == ''){
                    $('#feilei_error').show().text('请选择');
                    $('#feilei_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#feilei_error').hide();
                    $('#feilei_error').parent().find('input').removeClass('select_error');
                }

                formValid('duier');
                if(data.field.duier == undefined || !data.field.duier){
                    validRes = false;
                }

                if(!data.field.incdaotype){
                    $("#incdaotype").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#incdaotype").find('xm-select').removeClass('error');
                }

                formValid('accid');
                if(data.field.accid == undefined || !data.field.accid){
                    validRes = false;
                }

                var business = $("#business").val();
                if(business == 2){
                    if(data.field.iskou == ''){
                        $('#iskou_error').show().text('请选择');
                        $('#iskou_error').parent().find('input').addClass('select_error');
                        validRes = false;
                    }else{
                        $('#iskou_error').hide();
                        $('#iskou_error').parent().find('input').removeClass('select_error');
                    }
                }
                if(!validRes){return false;}
            }


            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var feitype = $(this).find('.feitype').val();
                    var money = $(this).find('.money').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!feitype){
                            throw new Error('第'+index+'行，请选择费用项');
                        }
                        if(money==''){
                            throw new Error('第'+index+'行，请输入到账金额');
                        }
                    }

                    list.push({
                        feitype:feitype,
                        money:money,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror_list").find('span').text(e.message);
                $(".listerror_list").show();
                return false;
            }
            $(".listerror_list").hide();
            data.field.list = list;


            var kou = [''];
            var business = $("#business").val();
            if(business == 2 && data.field.iskou == '是'){
                try {
                    $('#list_kou tr').each(function (i) {
                        var daikouqiid = $(this).find('.daikouqiid').attr('key') || 0;
                        if(daikouqiid > 0){
                            var feitype = $(this).find('.feitype').attr('key') || 0;
                        }else{
                            var feitype = $(this).find('.feitype').val();
                        }
                        var money = $(this).find('.money').val();
                        var explain = $(this).find('.explain').val();

                        var index = i + 1;
                        if(data.field.isturn > 0){
                            if(!feitype){
                                throw new Error('第'+index+'行，请选择费用项');
                            }
                            if(money==''){
                                throw new Error('第'+index+'行，请输入扣收金额');
                            }

                            if(daikouqiid > 0){
                                var chongKey = check_chongfu(i, daikouqiid);
                                if(chongKey){
                                    throw new Error('第'+chongKey+'行'+'与第'+index+'行，数据重复');
                                }
                            }
                        }

                        kou.push({
                            daikouqiid:daikouqiid,
                            feitype:feitype,
                            money:money,
                            explain:explain,
                        });
                    });
                } catch(e) {
                    $(".listerror_kou").find('span').text(e.message);
                    $(".listerror_kou").show();
                    return false;
                }
                $(".listerror_kou").hide();
                data.field.kou = kou;
            }


            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);

            public_flow_submit(data.field, ask_flowdata_add_shou_xiang, ask_flowdata_edit_shou_xiang, $(this).attr('but'));
            return false;
        });

    });

    //检测重复
    function check_chongfu(index, daikouqiid){
        try {
            $('#list_kou tr').each(function (i) {
                var cur_daikouqiid = $(this).find('.daikouqiid').attr('key') || 0;
                if(index != i){
                    if(daikouqiid == cur_daikouqiid){
                        throw new Error(i+1);
                    }
                }
            });
        } catch(e) {
            return e.message;
        }

        return 0;
    }

    $('#list_list').on('input propertychange','.money',function () {
        jisuan_money_all();
    });
    function jisuan_money_all() {
        var allmoney = 0;
        $('#list_list tr').each(function (i) {
            var money = parseFloat($(this).find('.money').val()) || 0;
            allmoney = parseFloat(allmoney) + parseFloat(money);
        });
        $("#money").val(allmoney);



        var lian_guanrate = parseValidNum($("#lian_guanrate").val() || 0) || 0;
        var benguanfee = 0;
        var feilei_text = $("#feilei option:selected").text();
        if(feilei_text == '工程回款'){
            benguanfee = parseFloat(parseFloat(allmoney) * parseFloat(lian_guanrate)/100).toFixed(2);
        }
        $("#benguanfee").val(benguanfee);

        var daikouallfee = parseValidNum($("#daikouallfee").val() || 0) || 0;
        var daikouhanfee = parseFloat(parseFloat(daikouallfee) + parseFloat(benguanfee)).toFixed(2);
        $("#daikouhanfee").val(daikouhanfee);

        // initParseMoney();
    }


    $('#list_kou').on('input propertychange','.money',function () {
        jisuan_koufee_all();
    });
    function jisuan_koufee_all() {
        var allkoufee = 0;
        var allkouguanfee = 0;
        var allkoushuifee = 0;
        var allkouqifee = 0;
        $('#list_kou tr').each(function (i) {
            var money = parseFloat($(this).find('.money').val()) || 0;
            var feitype = $(this).find('.feitype option:selected').text();
            if(feitype == '管理费'){
                allkouguanfee = parseFloat(allkouguanfee) + parseFloat(money);
            }else if(feitype == '税费'){
                allkoushuifee = parseFloat(allkoushuifee) + parseFloat(money);
            }else{
                allkouqifee = parseFloat(allkouqifee) + parseFloat(money);
            }
            allkoufee = parseFloat(allkoufee) + parseFloat(money);
        });
        $("#koufee").val(allkoufee);
        $("#kouguanfee").val(allkouguanfee);
        $("#koushuifee").val(allkoushuifee);
        $("#kouqifee").val(allkouqifee);
        // initParseMoney();
    }

    function update_refresh_row_func() {
        render_date();
        jisuan_money_all();
        jisuan_koufee_all();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        $.each($("#list_kou").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }





    function set_key1_add_str() {
        var feitype = [];
        var feilei = $("#feilei").val() || 0;
        for (var mmm in pub_feilei){
            if(pub_feilei[mmm].id == feilei){
                feitype = pub_feilei[mmm].children;
            }
        }

        var listAddStr = '';
        listAddStr += '<tr>';
        listAddStr += '<td style="width: 45px">1</td>';
        listAddStr += '<td><select class="layui-select feitype">';
        listAddStr += '<option value="">请选择</option>';
        for (var mmm in feitype) {
            listAddStr += '<option value="'+feitype[mmm].id+'">'+feitype[mmm].name+'</option>';
        }
        listAddStr += '</select></td>';
        listAddStr += '<td><input type="number" class="layui-input money"></td>';
        listAddStr += '<td><input type="text" class="layui-input explain"></td>';
        listAddStr += '</tr>';
        return listAddStr;
    }





</script>
</body>
</html>
